var content = http.get("https://gitee.com/lazy-voice-jmy/lsyp/raw/master/%E6%87%92%E5%A3%B0%E4%BA%91%E7%AB%AF")
if (content.statusCode == 200) {
    var main = content.body.string();
}

var window = floaty.window(
    <horizontal >
        <button id="action" text="开始运行" w="90" h="40" bg="#77ffffff"/>
    </horizontal>
);

setInterval(()=>{}, 1000);

var execution = null;

//记录按键被按下时的触摸坐标
var x = 0, y = 0;
//记录按键被按下时的悬浮窗位置
var windowX, windowY;
//记录按键被按下的时间以便判断长按等动作
var downTime;

window.action.setOnTouchListener(function(view, event){
    switch(event.getAction()){
        case event.ACTION_DOWN:
            x = event.getRawX();
            y = event.getRawY();
            windowX = window.getX();
            windowY = window.getY();
            downTime = new Date().getTime();
            return true;
        case event.ACTION_MOVE:
            //移动手指时调整悬浮窗位置
            window.setPosition(windowX + (event.getRawX() - x),
                windowY + (event.getRawY() - y));
            //如果按下的时间超过1.5秒判断为长按，退出脚本
            if(new Date().getTime() - downTime > 5000){
                exit();
            }
            return true;
        case event.ACTION_UP:
            //手指弹起时如果偏移很小则判断为点击
            if(Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5){
                onClick();
            }
            return true;
    }
    return true;
});


function onClick(){
    if(window.action.getText() == '开始运行'){
        execution = engines.execScript("统一弹奏", main)
        window.action.setText('长按拖动退出');
    }else{
        if(execution){
        execution = engines.execScript("统一弹奏", main)
        }
        window.action.setText('开始运行');
    }
}var content = http.get("https://gitee.com/lazy-voice-jmy/lsyp/raw/master/%E6%87%92%E5%A3%B0%E4%BA%91%E7%AB%AF")
if (content.statusCode == 200) {
        var main = content.body.string();
}

var window = floaty.window(
        <horizontal >
                <button id="action" text="开始运行" w="90" h="40" bg="#77ffffff"/>
                    </horizontal>
);

setInterval(()=>{}, 1000);

var execution = null;

//记录按键被按下时的触摸坐标
var x = 0, y = 0;
//记录按键被按下时的悬浮窗位置
var windowX, windowY;
//记录按键被按下的时间以便判断长按等动作
var downTime;

window.action.setOnTouchListener(function(view, event){
        switch(event.getAction()){
                    case event.ACTION_DOWN:
                                x = event.getRawX();
                                            y = event.getRawY();
                                                        windowX = window.getX();
                                                                    windowY = window.getY();
                                                                                downTime = new Date().getTime();
                                                                                            return true;
                                                                                                    case event.ACTION_MOVE:
                                                                                                                //移动手指时调整悬浮窗位置
                                                                                                                            window.setPosition(windowX + (event.getRawX() - x),
                                                                                                                                            windowY + (event.getRawY() - y));
                                                                                                                                                        //如果按下的时间超过1.5秒判断为长按，退出脚本
                                                                                                                                                                    if(new Date().getTime() - downTime > 5000){
                                                                                                                                                                                        exit();
                                                                                                                                                                    }
                                                                                                                                                                                return true;
                                                                                                                                                                                        case event.ACTION_UP:
                                                                                                                                                                                                    //手指弹起时如果偏移很小则判断为点击
                                                                                                                                                                                                                if(Math.abs(event.getRawY() - y) < 5 && Math.abs(event.getRawX() - x) < 5){
                                                                                                                                                                                                                                    onClick();
                                                                                                                                                                                                                }
                                                                                                                                                                                                                            return true;
        }
            return true;
});


function onClick(){
        if(window.action.getText() == '开始运行'){
                    execution = engines.execScript("统一弹奏", main)
                            window.action.setText('长按拖动退出');
        }else{
                    if(execution){
                                execution = engines.execScript("统一弹奏", main)
                    }
                            window.action.setText('开始运行');
        }
}
                    }
        }
        }
}
                                                                                                                                                                                                                }
                                                                                                                                                                    }
        }
})
)
}